﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class cms_cmsHome : System.Web.UI.Page
{
    private const string ImageBanner = "banner.png";
    private const string ButtonContactUs = "schedule-button.png";
    private const string ImageWhatCan = "what-can-mobile.jpg";
    private const string ImageHowCan = "home-add.jpg";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadImageDesign();
        }
    }

    private void LoadImageDesign()
    {
        if (File.Exists(Server.MapPath("~/images/" + ImageBanner)))
        {
            imgBanner.ImageUrl = "~/images/" + ImageBanner;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ImageBanner));
            lblSize.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
        if (File.Exists(Server.MapPath("~/images/" + ButtonContactUs)))
        {
            imgContactUs.ImageUrl = "~/images/" + ButtonContactUs;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ButtonContactUs));
            lblSizeContact.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
        if (File.Exists(Server.MapPath("~/images/" + ImageWhatCan)))
        {
            imgWhatCan.ImageUrl = "~/images/" + ImageWhatCan;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ImageWhatCan));
            lblSizeWhatCan.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
        if (File.Exists(Server.MapPath("~/images/" + ImageHowCan)))
        {
            imgHowCan.ImageUrl = "~/images/" + ImageHowCan;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ImageHowCan));
            lblSizeHowCan.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (FileUploadBanner.HasFile && Utils.IsImageFile(FileUploadBanner.FileName))
        {
            FileUploadBanner.SaveAs(Server.MapPath("~/images/" + ImageBanner));
        }
        if (FileUploadContactUs.HasFile && Utils.IsImageFile(FileUploadContactUs.FileName))
        {
            FileUploadContactUs.SaveAs(Server.MapPath("~/images/" + ButtonContactUs));
        }
        if (FileUploadHowCan.HasFile && Utils.IsImageFile(FileUploadHowCan.FileName))
        {
            FileUploadHowCan.SaveAs(Server.MapPath("~/images/" + ImageHowCan));
        }
        if (FileUploadWhatCan.HasFile && Utils.IsImageFile(FileUploadWhatCan.FileName))
        {
            FileUploadWhatCan.SaveAs(Server.MapPath("~/images/" + ImageWhatCan));
        }
    }
}